package me.chinaq.fastweb.web;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.IOException;

/**
 * Created by shaoqi on 9/6/2017.
 */
@WebFilter
public class XssFilter implements Filter {
	private FilterConfig filterConfig;

	public void destroy() {
		this.filterConfig = null;
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
						 FilterChain chain) throws IOException, ServletException {
		System.out.println("=====================================Filter");
		chain.doFilter(new XssRequestWrapper((HttpServletRequest) request), response);
	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		this.filterConfig = filterConfig;
	}

	private class XssRequestWrapper extends HttpServletRequestWrapper {
		/**
		 * Constructs a request object wrapping the given request.
		 *
		 * @param request The request to wrap
		 * @throws IllegalArgumentException if the request is null
		 */
		public XssRequestWrapper(HttpServletRequest request) {
			super(request);
		}
	}


}
